package com.vanke.devops.api.controller.schedulejob;

import com.vanke.core.bean.ApiBaseResponse;
import com.vanke.devops.api.base.AbstractController;
import com.vanke.devops.api.controller.schedulejob.form.ScheduleJobForm;
import com.vanke.devops.domain.domain.schedulejob.IScheduleJobService;
import com.vanke.devops.domain.domain.schedulejob.param.ScheduleJobParam;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

/**
 * @author 陈景阳
 * @since 2018/6/8
 */
@RestController
@RequestMapping("/schedule-job")
public class ScheduleJobController extends AbstractController<IScheduleJobService>{

    @GetMapping("/page/{pageNo}/{pageSize}")
    public ApiBaseResponse page(@PathVariable("pageNo") Integer pageNo,
                                @PathVariable("pageSize") Integer pageSize){
        return setResponse(service.page(pageNo,pageSize));
    }

    @GetMapping("/{id}")
    public ApiBaseResponse getInfo(@PathVariable("id") Integer id){
        return setResponse(service.getInfo(id));
    }

    @PostMapping
    public ApiBaseResponse add(@RequestBody ScheduleJobForm form){
        ScheduleJobParam param = new ScheduleJobParam();
        BeanUtils.copyProperties(form,param);
        return setResponse(service.add(param));
    }

    @PutMapping("/{id}")
    public ApiBaseResponse update(@PathVariable("id") Integer id,
                                  @RequestBody ScheduleJobForm form){
        ScheduleJobParam param = new ScheduleJobParam();
        BeanUtils.copyProperties(form,param);
        return setResponse(service.update(id,param));
    }

    @PostMapping("/delete")
    public ApiBaseResponse delete(@RequestBody Integer[] jobIds){
        service.deleteBatch(jobIds);
        return setResponse();
    }
    @PostMapping("/run")
    public ApiBaseResponse run(@RequestBody Integer[] jobIds){
        service.run(jobIds);
        return setResponse();
    }

    @PostMapping("/pause")
    public ApiBaseResponse pause(@RequestBody Integer[] jobIds){
        service.pause(jobIds);
        return setResponse();
    }

    @PostMapping("/resume")
    public ApiBaseResponse resume(@RequestBody Integer[] jobIds){
        service.resume(jobIds);
        return setResponse();
    }

}
